from odoo import fields, models, api
from odoo.exceptions import UserError


class RpRegisterMock(models.TransientModel):
    _name = 'rp.register'
    _description = '注册'

    last_name = fields.Char(string='性')
    first_name = fields.Char(string='名')
    user_name = fields.Char(string='用户名')
    password = fields.Char(string='密码')
    invite_code = fields.Char(string='邀请码')

    def register_customer(self):
        self.ensure_one()
        # 创建记录
        if all([self.last_name, self.first_name, self.user_name, self.password]):
            data = {
                'last_name': self.last_name,
                'first_name': self.first_name,
                'username': self.user_name,
                'password': self.password
            }
            res_person = self.env['rp.customer'].create([data])
            self._cr.commit()
            return res_person
        else:
            raise UserError('请填写完有效信息后重试！')
